package cn.hanyx.coder.design.pattern.behavioral.observer.demo01;

import java.util.ArrayList;
import java.util.List;

/**
 * ConcreteSubject
 * 被依赖者 , 被观察者 实现类
 *
 * @author hanyx
 * @date 2020/06/02
 */
public class ConcreteSubject implements Subject {
    private List<Observer> observers = new ArrayList<>();

    @Override
    public void registerObjserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObjserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObjservers(Message msg) {
        observers.forEach(observer -> observer.update(msg));
    }
}
